package com.iris.live.services.data.models;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @Description:报表配置
 * @author: Tony.Zhang
 * @Date: 2017-08-11 11:23
 **/
@Entity
@Table(name = "t_rpt_config_info", schema = "", catalog = "")
public class ReportConfig implements Serializable {
    private Integer id;//自增id
    private  String reportCode;// 例如 ：销售管理报表
    private String ainCode;//对应数据库自节点code
    private String parentCode;//父节点code
    private String category; //统计纬度类型，比如销售管理报表中品牌，具体指标。
    private String valueKey; //数据KEY
    private String matchKey; //统计纬度对应的数据库字段
    private String text;     //统计纬度显示名称
    private String formularExpression; //如果当前行数据是通过公式自动计算的，该值定义了计算公式
    private String remark;
    private Date createTime;
    private String updateBy;
    private String createBy;
    private Date updateTime;
    private String projectNameOrder;//前端排序id
    private Integer isDeleted;
    private List<ReportConfig> childConfigs; //子类配置项
    private ReportConfig parentConfig; //父类配置项
    private int matchItem = 0; //是否是数据匹配项
    private int matcher = 0; //匹配器， 1：equals  2：include
    private String dataType = "double";   //类型, double, int , String
    private int    precious = 2;   //精度, 2
    private int    rowType = 0; //0:普通行 1：公式行 2：空行
    private Integer    priority ; //计算优先级，缺省都是1， 主要用来，解决公式嵌套时执行顺序问题
    private String  statType ; //统计类型: 品牌:按照品牌统计，累计：累计统计

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Basic
    @Column(name = "report_code")
    public String getReportCode() {
        return reportCode;
    }

    public void setReportCode(String reportCode) {
        this.reportCode = reportCode;
    }

    @Basic
    @Column(name = "code")
    public String getAinCode() {
        return ainCode;
    }

    public void setAinCode(String ainCode) {
        this.ainCode = ainCode;
    }

    @Column(name="father_code")
    public String getParentCode() {
        return parentCode;
    }

    public void setParentCode(String parentCode) {
        this.parentCode = parentCode;
    }

    @Column(name="type_name")
    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    @Basic
    @Column(name="db_colum")
    public String getMatchKey() {
        return matchKey == null ? "" : matchKey.trim();
    }

    public void setMatchKey(String matchKey) {
        this.matchKey = matchKey;
    }

    @Basic
    @Column(name="show_ch_name")
    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    @Basic
    @Column(name = "formular" )
    public String getFormularExpression() {
        return formularExpression;
    }

    public void setFormularExpression(String formularExpression) {
        this.formularExpression = formularExpression;
    }

    @Basic
    @Column(name = "remark" )
    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @Basic
    @Column(name = "create_by" )
    public String getCreateBy() {
        return this.createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    @Basic
    @Column(name = "create_time" )
    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Basic
    @Column(name = "update_by", nullable = false, length = 300)
    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    @Basic
    @Column(name = "update_time", nullable = false)
    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    @Basic
    @Column(name = "is_deleted", nullable = false)
    public Integer getIsDeleted() {
        return isDeleted;
    }

    public void setIsDeleted(Integer isDeleted) {
        this.isDeleted = isDeleted;
    }

    @Basic
    @Column(name = "order_id", nullable = false)
    public String getProjectNameOrder() {
        return projectNameOrder;
    }

    public void setProjectNameOrder(String projectNameOrder) {
        this.projectNameOrder = projectNameOrder;
    }


    @Transient
    public List<ReportConfig> getChildConfigs() {
        return childConfigs;
    }

    public void setChildConfigs(List<ReportConfig> childConfigs) {
        this.childConfigs = childConfigs;
    }

    @Transient
    public ReportConfig getParentConfig() {
        return parentConfig;
    }

    public void setParentConfig(ReportConfig parentConfig) {
        this.parentConfig = parentConfig;
    }

    @Transient
    public boolean isFormular(){
        return formularExpression != null && !formularExpression.trim().equals("");
    }

    @Basic
    @Column(name = "match_item", nullable = false)
    public int getMatchItem() {
        return matchItem;
    }

    public void setMatchItem(int matchItem) {
        this.matchItem = matchItem;
    }

    @Transient
    public String getValueKey() {
        return valueKey == null ? this.getMatchKey() : this.valueKey.trim();
    }

    public void setValueKey(String valueKey) {
        this.valueKey = valueKey;
    }

    @Basic
    @Column(name = "matcher", nullable = false)
    public int getMatcher() {
        return matcher;
    }

    public void setMatcher(int matcher) {
        this.matcher = matcher;
    }

    @Basic
    @Column(name = "DATA_TYPE", nullable = false)
    public String getDataType() {
        return dataType;
    }

    public void setDataType(String dataType) {
        this.dataType = dataType;
    }

    @Basic
    @Column(name = "DATA_PRECIOUS", nullable = false)
    public int getPrecious() {
        return precious;
    }

    public void setPrecious(int precious) {
        this.precious = precious;
    }

    @Basic
    @Column(name = "ROW_TYPE", nullable = false)
    public int getRowType() {
        return formularExpression != null?1:rowType;
    }

    public void setRowType(int rowType) {
        this.rowType = rowType;
    }

    @Basic
    @Column(name = "PRIORITY", nullable = false)
    public Integer getPriority() {
        return priority == null ? 1 : priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    @Basic
    @Column(name = "STAT_TYPE", nullable = false)
    public String getStatType() {
        return statType;
    }

    public void setStatType(String statType) {
        this.statType = statType;
    }

    @Transient
    public boolean isBlank(){
        return getRowType() == 2;
    }
}
